fix(prime-random): replace poisson_disk_2d with O(1) poisson_disk#43
Open
bwyard wants to merge 1 commit into
Open
fix(prime-random): replace poisson_disk_2d with O(1) poisson_disk#43bwyard wants to merge 1 commit into
bwyard wants to merge 1 commit into
Conversation
The old poisson_disk_2d cloned the entire spatial grid (O(cols×rows)) on every accepted point via the pure-fold successors chain. At 500×500 with min_dist=5, that's ~40,000 clones per step — 8.6× slower than necessary. The new poisson_disk uses internal mutation with O(1) grid access while keeping the external contract pure (same seed → same output, always). Signature simplified: seed moved to last arg, no seed returned (pure functions don't thread state out). - Remove BridsonState/BridsonParams/bridson_step infrastructure (fold-only) - Add poisson_disk(width, height, min_dist, max_attempts, seed) -> Vec - Update all unit tests; replace poisson_disk_returns_seed with poisson_disk_empty_on_invalid_input (new guard tested) - Update bench: add 500×500 size, rename group to poisson_disk - Update prime-wasm binding to match new signature Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
poisson_disk_2dcloned the full spatial grid (O(cols×rows)) on every accepted point via the pure-foldsuccessorschain — a hidden performance bug that got worse non-linearly with domain sizepoisson_diskuses internal mutation with O(1) grid access; external contract stays pure (same seed → same output)Benchmark (min_dist=5.0, seed=42, k=30)
Speedup is non-linear because grid clone cost scales with domain area while the fix is O(1).
Test plan
cargo test -p prime-random— 27 tests passcargo build -p prime-wasm— builds cleanpoisson_disk(100.0, 100.0, 10.0, 30, 42)produces same points as oldpoisson_disk_2d(42, 100.0, 100.0, 10.0, 30)🤖 Generated with Claude Code